import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { viteMockServe } from 'vite-plugin-mock'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

export default defineConfig(({ command }) => {
  return {
  plugins: [vue(),
    viteMockServe({
      // 保证开发阶段可以使用mock接口
      localEnabled: command === 'serve',
    }),  
  ],
  //解决“vite use `--host` to expose”
  base: './',
  server: {             
    host: '0.0.0.0',	
    port: 8080,      
    open: true
  },
  resolve:{   
    //别名配置，引用src路径下的东西可以通过@如：import Layout from '@/layout/index.vue'
    alias:[   
      {
        find:'@',
        replacement:resolve(__dirname,'src') 
      }
    ]
  },
  
  css: {
    // CSS 预处理器
    preprocessorOptions: {
        // 定义全局 SCSS 变量
        scss: {
            javascriptEnabled: true,
            additionalData: "@use '/src/styles/variables.scss' as *;",
        },
    },
},
createSvgIconsPlugin({
  // Specify the icon folder to be cached
  iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
  // Specify symbolId format
  symbolId: 'icon-[dir]-[name]',
}),

}
});
